package com.lizhongbao.cloud.gateway.filter;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * @ClassName RouteLocatorConfig
 * @Description 自定义过滤器
 * @Author lizhongbao
 * @Date 2019/12/6 11:13
 * @Version 1.0
 **/
@Configuration
public class RouteLocatorConfig {
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        System.out.println("============================RouteLocatorConfig "+ builder.routes());
        return builder.routes()
                .route(r -> r.path("/server-provider/**")
                        .filters(f -> f.filter(new LimitFilter(5,20, Duration.ofSeconds(1)))
                            .addResponseHeader("X-Response-Default-Foo", "Default-Bar").stripPrefix(1))
                        .uri("lb://server-provider")
                        .order(0)
                        .id("server-provider")
                )
                .build();
    }
}
